<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>自由讨论</title>
    <link rel="stylesheet" href="../layui/css/layui.css">
    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
    <style type="text/css" >
        .layui-tab-brief>.layui-tab-title .layui-this {
            color: #0B469F;
        }
        .layui-tab-brief>.layui-tab-title .layui-this:after {
            border-bottom: 2px solid #0B469F;
        }
        #first{
            margin: 0 auto;
            width: 950px;
            background-color: #F6F6F8;
        }
    </style>
</head>
<body>
<div id="title" style="margin-bottom: 10px;margin-top: 15px;padding-bottom: 20px;">
<!--    <h2 align="center">关于软件工程的相关问题</h2>-->
</div>
<div id="first" style="margin-top: 10px;">

</div>
<div class="distinction">
    <form class="layui-form" action="">
        <div class="layui-form-item layui-form-text">
            <div class="layui-input-block">
                <p style="margin-left: 270px">回复他</p>
                <textarea style="width: 950px;margin-left: 270px" id="context" name="desc" placeholder="请输入内容" class="layui-textarea"></textarea>
            </div>
        </div>
        <div class="layui-upload-button" style="margin-left: 800px">
            <button type="button" style="background-color: #0B469F" class="layui-btn" onclick="submt()" id="upload">提交</button>
            <button type="button" style="background-color: #0B469F" class="layui-btn" onclick="retur()" id="return0" >返回</button>
        </div>
    </form>
</div>
<script type="text/javascript" src="../layui/layui.js"></script>
<script>
    function retur(){
        location.href='常见问题.html';
    }
    function submt(){
        var context = document.getElementById("context").value;
        $.ajax({
            url:'http://106.14.215.182:9091/tby/ipos-discussion-publisher/returnContent',
            headers: {
                token:localStorage.getItem("token"),
            },
            type:"POST",
            data:JSON.stringify({
                publisherId:localStorage.getItem("publisherId"),
                topic:localStorage.getItem("topic"),
                returnContent:context
            }),
            contentType: 'application/json',
            dataType: 'json',
            success:function (result) {
                console.log(result);
                if(result.success == false){
                    // alert(result.data);
                    layui.use('layer',function(){
                        var layer=layui.layer;
                        layer.msg(result.data,{
                            icon:2,
                            area:['180px','64px'],
                            time:3000
                        });
                    });
                }else{
                    // alert("回复成功");
                    layui.use('layer',function(){
                        var layer=layui.layer;
                        layer.msg('回复成功！',{
                            icon:1,
                            area:['180px','64px'],
                            time:3000
                        });
                    });
                }
            }
        })
    }
    window.onload = function () {
        var topic = localStorage.getItem("topic");
        var publisherId = localStorage.getItem("publisherId");
        $.ajax({
            url:'http://106.14.215.182:9091/tby/ipos-discussion-publisher/getContext',
            type:"POST",
            data:JSON.stringify({
                topic:topic,
                publisherId:publisherId,
                returnContent:''
            }),
            contentType: 'application/json',
            dataType: 'json',
            success:function (result) {
                console.log(result)
                var ttitle = $("#title");
                var tbody = $("#first");
                $('#first').empty();
                var data = result.data;
                var obj1 = new Object();
                var obj2 = new Object();
                if(data.context.length == 0){
                    var html1 = '';
                    html1 = html1 + '    <h2 align="center">'+topic+'</h2>\n' +
                        '<hr style="margin: 0 auto;width: 950px;">'
                    ttitle.append(html1);
                    ttitle.innerHTML = html1;
                }
                else
                {
                    var html='';
                    for(var i =0 ;i<data.context.length;i++){
                        var html1 ='';
                        obj1[i] = data.context[i];
                        obj2[i] = data.returnUserId[i];
                        if(i == 0){
                            var html1 = '';
                            html1 = html1 + '    <h2 align="center">'+topic+'</h2>\n' +
                                '<hr style="margin: 0 auto;width: 950px">'
                            ttitle.append(html1);
                            ttitle.innerHTML = html1;
                            html =html+  '<div style="height: 100px;">\n' +
                                '                    <div style="padding-top: 20px;padding-left: 20px">\n' +
                                '                    <p style="color: red;display: inline-block">发表人: '+obj2[i]+'</p>\n' +
                                '                    <p style="display: inline-block;font-size: 18px;margin-left: 50px "><a  style="color:#2D64B3">'+obj1[i]+'</a></p>\n' +
                                '                    </div>\n' +
                                '                </div>\n' +
                                '                <hr>';
                        }
                        else
                        {
                            html =html+  '<div style="height: 100px">\n' +
                                '                    <div style="padding-top: 20px;padding-left: 20px">\n' +
                                '                    <p style="color: red;display: inline-block">回复人: '+obj2[i]+'</p>\n' +
                                '                    <p style="display: inline-block;font-size: 18px;margin-left: 50px "><a  style="color:#2D64B3">'+obj1[i]+'</a></p>\n' +
                                '                    </div>\n' +
                                '                </div>\n' +
                                '                <hr>';
                        }
                        console.log(html)
                    }
                    tbody.append(html);
                    tbody.innerHTML = html;
                }
            }
        })
    }
</script>
</body>
</html>